var e = require("../../../../../common/vendor.js"), n = require("../config/index.js"), t = require("./z-paging-constant.js"), r = "Z-PAGING-REFRESHER-TIME-STORAGE-KEY", o = null, c = !1, a = {};

function i() {
    return e.index.getStorageSync(r);
}

function u() {
    return new Date().getTime();
}

function g(e) {
    return 1 === (e = e.toString()).length ? "0" + e : e;
}

var l = {
    gc: function(t, r) {
        if (c || (n.zLocalConfig && Object.keys(n.zLocalConfig).length && (o = n.zLocalConfig), 
        !o && e.index.$zp && (o = e.index.$zp.config), o = o ? Object.keys(o).reduce(function(e, n) {
            return e[function(e) {
                return e.replace(/-([a-z])/g, function(e, n) {
                    return n.toUpperCase();
                });
            }(n)] = o[n], e;
        }, {}) : null, c = !0), !o) return r;
        var a = o[t];
        return void 0 === a ? r : a;
    },
    setRefesrherTime: function(n, t) {
        var o = i() || {};
        o[t] = n, e.index.setStorageSync(r, o);
    },
    getRefesrherFormatTimeByKey: function(e, n) {
        var t = function(e) {
            var n = i();
            return n && n[e] ? n[e] : null;
        }(e), r = t ? function(e, n) {
            var t, r = new Date(e), o = new Date(), c = new Date(e).setHours(0, 0, 0, 0) - new Date().setHours(0, 0, 0, 0), a = function(e) {
                var n = e.getHours(), t = e.getMinutes();
                return "".concat(g(n), ":").concat(g(t));
            }(r);
            return t = 0 === c ? n.today : -864e5 === c ? n.yesterday : function(e) {
                var n = !(arguments.length > 1 && void 0 !== arguments[1]) || arguments[1], t = e.getFullYear(), r = e.getMonth() + 1, o = e.getDate();
                return n ? "".concat(t, "-").concat(g(r), "-").concat(g(o)) : "".concat(g(r), "-").concat(g(o));
            }(r, r.getFullYear() !== o.getFullYear()), "".concat(t, " ").concat(a);
        }(t, n) : n.none;
        return "".concat(n.title).concat(r);
    },
    getTouch: function(e) {
        var n = null;
        if (e.touches && e.touches.length) n = e.touches[0]; else if (e.changedTouches && e.changedTouches.length) n = e.changedTouches[0]; else {
            if (!e.datail || e.datail == {}) return {
                touchX: 0,
                touchY: 0
            };
            n = e.datail;
        }
        return {
            touchX: n.clientX,
            touchY: n.clientY
        };
    },
    getTouchFromZPaging: function e(n) {
        if (n && n.tagName && "BODY" !== n.tagName && "UNI-PAGE-BODY" !== n.tagName) {
            var t = n.classList;
            return t && t.contains("z-paging-content") ? {
                isFromZp: !0,
                isPageScroll: t.contains("z-paging-content-page"),
                isReachedTop: t.contains("z-paging-reached-top")
            } : e(n.parentNode);
        }
        return {
            isFromZp: !1
        };
    },
    getParent: function e(n) {
        return n ? n.$refs.paging ? n : e(n.$parent) : null;
    },
    convertToPx: function(n) {
        if ("[object Number]" === Object.prototype.toString.call(n)) return n;
        var t = !1;
        return -1 !== n.indexOf("rpx") || -1 !== n.indexOf("upx") ? (n = n.replace("rpx", "").replace("upx", ""), 
        t = !0) : -1 !== n.indexOf("px") && (n = n.replace("px", "")), isNaN(n) ? 0 : Number(t ? e.index.upx2px(n) : n);
    },
    getTime: u,
    getInstanceId: function() {
        for (var e = [], n = 0; n < 10; n++) e[n] = "0123456789abcdef".substr(Math.floor(16 * Math.random()), 1);
        return e.join("") + u();
    },
    consoleErr: function(e) {
        console.error("[z-paging]".concat(e));
    },
    delay: function(e) {
        var n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : t.c.delayTime, r = arguments.length > 2 ? arguments[2] : void 0, o = setTimeout(e, n);
        return r && (a[r] && clearTimeout(a[r]), a[r] = o), o;
    },
    wait: function(e) {
        return new Promise(function(n) {
            setTimeout(n, e);
        });
    }
};

exports.u = l;